//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "Sweden.h"
using namespace Cephei::QL::Times::Calendars;
#include <gen/QL/Times/Period.h>
#include <gen/QL/Times/Calendar.h>
using namespace Cephei::QL::Times;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Times::Calendars::CSweden::CSweden () : CCalendar(CSweden::typeid)
{
    try
    {
#ifdef HANDLE
        _phSweden = NULL;
#endif
        _ppSweden = new boost::shared_ptr<QuantLib::Sweden> (new QuantLib::Sweden ( ));
        SetCalendar (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppSweden));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::Calendars::CSweden::CSweden (boost::shared_ptr<QuantLib::Sweden>& childNative, Object^ owner) : CCalendar(CSweden::typeid)
{
#ifdef HANDLE
	_phSweden = NULL;
#endif
	_ppSweden = &childNative;
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppSweden));
}
Cephei::QL::Times::Calendars::CSweden::CSweden (QuantLib::Sweden& childNative, Object^ owner) : CCalendar(CSweden::typeid)
{
#ifdef HANDLE
	_phSweden = NULL;
#endif
	_ppSweden = new boost::shared_ptr<QuantLib::Sweden> (&childNative);
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppSweden));
    _SwedenOwner = owner;
    _CalendarOwner = owner;
}

Cephei::QL::Times::Calendars::CSweden::CSweden (CSweden^ copy) : CCalendar(CSweden::typeid)
{
#ifdef HANDLE
	_phSweden = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppSweden = new boost::shared_ptr<QuantLib::Sweden> (copy->GetShared());
        _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppSweden));
    }
}
Cephei::QL::Times::Calendars::CSweden::CSweden (PLATFORM::Type^ t) : CCalendar(CSweden::typeid)
{
#ifdef HANDLE
	_phSweden = NULL;
#endif
	if (!t->IsSubclassOf(CSweden::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Times::Calendars::CSweden::CSweden (QuantLib::Handle<QuantLib::Sweden>& childNative, Object^ owner)  : CCalendar(CSweden::typeid)
{
	_phSweden = &childNative;
	_ppSweden = &static_cast<boost::shared_ptr<QuantLib::Sweden>>(childNative.currentLink());
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppSweden));
    _SwedenOwner = owner;
}
Cephei::QL::Times::Calendars::CSweden::CSweden (QuantLib::Handle<QuantLib::Sweden> childNative)  : CCalendar(CSweden::typeid)
{
	_phSweden = &childNative;
	_ppSweden = &static_cast<boost::shared_ptr<QuantLib::Sweden>>(childNative.currentLink());
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppSweden));
}
#endif
#ifdef STRUCT
Cephei::QL::Times::Calendars::CSweden::CSweden (QuantLib::Sweden childNative)  : CCalendar(CSweden::typeid)
{
#ifdef HANDLE
	_phSweden = NULL;
#endif
	_ppSweden = new boost::shared_ptr<QuantLib::Sweden> (new QuantLib::Sweden (childNative));
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppSweden));
}
#endif

Cephei::QL::Times::Calendars::CSweden::~CSweden ()
{
    if (_ppSweden != NULL)
    {
	    delete _ppSweden;
        _ppSweden = NULL;
    }
}
Cephei::QL::Times::Calendars::CSweden::!CSweden ()
{
    if (_ppSweden != NULL)
    {
	    delete _ppSweden;
    }
}
QuantLib::Sweden& Cephei::QL::Times::Calendars::CSweden::GetReference ()
{
    if (_ppSweden == NULL) throw REFNEW NativeNullException ();
	return **_ppSweden;
}
boost::shared_ptr<QuantLib::Sweden>& Cephei::QL::Times::Calendars::CSweden::GetShared ()
{
    if (_ppSweden == NULL) throw REFNEW NativeNullException ();
	return *_ppSweden;
}
QuantLib::Sweden* Cephei::QL::Times::Calendars::CSweden::GetPointer ()
{
    if (_ppSweden == NULL) throw REFNEW NativeNullException ();
	return &**_ppSweden;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::Sweden>& Cephei::QL::Times::Calendars::CSweden::GetHandle ()
{
	if (_phSweden == NULL)
	{
		_phSweden = new Handle<QuantLib::Sweden> (*_ppSweden);
	}
	return *_phSweden;
}
#endif
bool Cephei::QL::Times::Calendars::CSweden::HasNative () 
{
	return (_ppSweden != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Times::Calendars::ISweden^ Cephei::QL::Times::Calendars::CSweden_Factory::Create ()
{
    return REFNEW CSweden ();
}
